function isInteger(str){
	var val1 = 1*str;
	var val2 = parseInt(str);
	if (isNaN(val1)||isNaN(val2)){
		return false;
	} else {
		return true;
	}
}
function isDouble(str){
	var val1 = 1*str;
	var val2 = parseFloat(str);
	if (isNaN(val1)||isNaN(val2)){
		return false;
	} else {
		return true;
	}
}

function arrayAverage(array){
	var sum = 0;
	var count = 0;
	for(var i=0;i<array.size();i++){
		if(isDouble(array[i])){
			sum += parseFloat(array[i]);
			count++;
		}
	}
	if (count != 0)
		return sum/count;
	else return 0;
}

function average(inputName){
	var inputs = document.getElementsByName(inputName);
	
	var sum = 0;
	var count = 0;
	for(var i=0;i<inputs.length;i++){
		if(isDouble(inputs[i].value)){
			sum += parseFloat(inputs[i].value);
			count++;
		}
	}
	if (count != 0)
		return sum/count;
	else return 0;
}

function maxValue(inputName){
	var inputs = document.getElementsByName(inputName);
	
	var mv = 0;
	var count = 0;
	for(var i=0;i<inputs.length;i++){
		if(isDouble(inputs[i].value)){
			var val = parseFloat(inputs[i].value);
			if(count==0){
				mv = val;
			}else{
				if(val>mv) mv=val;
			}
			count++;
		}
	}
	return mv;
}

function maxValueInput(inputName){
	var inputs = document.getElementsByName(inputName);
	var ind = -1;

	var mv = 0;
	var count = 0;
	for(var i=0;i<inputs.length;i++){
		if(isDouble(inputs[i].value)){
			var val = parseFloat(inputs[i].value);
			if(count==0){
				ind = i;
				mv = val;
			}else if(val>mv){
				ind = i;
				mv = val;
			}
			count++;
		}
	}
	
	if(ind>=0)return inputs[ind];
	else return NaN;
}

function minValue(inputName){
	var inputs = document.getElementsByName(inputName);
	
	var mv = 0;
	var count = 0;
	for(var i=0;i<inputs.length;i++){
		if(isDouble(inputs[i].value)){
			var val = parseFloat(inputs[i].value);
			if(count==0){
				mv = val;
			}else{
				if(val<mv) mv=val;
			}
			count++;
		}
	}
	return mv;
}

function minValueInput(inputName){
	var inputs = document.getElementsByName(inputName);
	var ind = -1;

	var mv = 0;
	var count = 0;
	for(var i=0;i<inputs.length;i++){
		if(isDouble(inputs[i].value)){
			var val = parseFloat(inputs[i].value);
			if(count==0){
				ind = i;
				mv = val;
			}else if(val<mv){
				ind = i;
				mv = val;
			}
			count++;
		}
	}

	if(ind>=0)return inputs[ind];
	else return NaN;
}

function setAllInput(inputName,att,val){
	var inputs = document.getElementsByName(inputName);
	for(var i=0;i<inputs.length;i++){
		try{
			eval('inputs[i].'+att+'=\''+val+'\';');
		}catch(exception){}
	}
}

function setOneInput(inp,att,val){
	try{
		eval('inp.'+att+'=\''+val+'\';');
	}catch(exception){}
}